local function lightson(inst)
    if inst._light then
        inst._light:FadeIn()
    end
end

local function lightsoff(inst)
    if inst._light then
        inst._light:FadeOut()
    end
end

local function onequip(inst, owner)
    local skin_build = inst:GetSkinBuild()
    if skin_build ~= nil then
        owner:PushEvent("equipskinneditem", inst:GetSkinName())
        owner.AnimState:OverrideItemSkinSymbol("swap_object", skin_build, "swap_candybag", inst.GUID, "swap_candy")
    else
        owner.AnimState:OverrideSymbol("swap_object", "swap_candybag", "swap_candy")
    end
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")

    if inst.components.container ~= nil then
        inst.components.container:Open(owner)
    end
    lightson(inst)
end

local function onunequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
    local skin_build = inst:GetSkinBuild()
    if skin_build ~= nil then
        owner:PushEvent("unequipskinneditem", inst:GetSkinName())
    end

    if inst.components.container ~= nil then
        inst.components.container:Close()
    end
    lightsoff(inst)
end

local seg_time = 30
local mins = seg_time * 2

local function isspring()
    return TheWorld.state.isspring
end

local function issummer()
    return TheWorld.state.issummer
end

local function isfall()
    return TheWorld.state.isautumn
end

local function iswinter()
    return TheWorld.state.iswinter
end

local modsenabled = KnownModIndex:GetModsToLoad(true)
local enabledmods = {}
for k, dir in pairs(modsenabled) do
    local info = KnownModIndex:GetModInfo(dir)
    local name = info and info.name or "unknown"
    enabledmods[dir] = name
end
local function IsModEnable(name)
    for k, v in pairs(enabledmods) do
        if v and (k:match(name) or v:match(name)) then
            return true
        end
    end
    return false
end
local ENABLEDMODS = {}
ENABLEDMODS.tastefun = IsModEnable("TasteFun") or IsModEnable("食趣") -- 食趣

local foods = {
    -- 松子咖啡
    -- ————检查台词：松果做的咖啡！好喝！
    -- 1蜂蜜，2松果，1冰
    -- +25饱食，+5san，+5血
    -- 保质期20天
    -- 提供降温15秒，20%加速4分钟
    nuts_coffe =
    {
        test = function(cooker, names, tags)
            return tags.sweetener
                and names.pinecone and names.pinecone > 1
                and tags.frozen
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = TUNING.CALORIES_MED,
        sanity = TUNING.SANITY_TINY,
        health = 5,
        perishtime = 5 * TUNING.PERISH_ONE_DAY,
        perishfood = "nuts_coldcoffe",
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        scale = .9,
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_speed", "nutsbuff_speed")
        end,
        temperature = TUNING.COLD_FOOD_BONUS_TEMP,
        temperatureduration = TUNING.FOOD_TEMP_LONG
    },

    -- 冰咖啡
    -- ————本角色检查台词：可以闻到又香又浓的松子的味道！
    -- ————其他角色检查台词：松果做的咖啡！好喝！
    -- 松子咖啡腐烂后变成这个
    -- +25饱食，+5san，+5血
    -- 保质期10天
    -- 提供降温15秒，20%加速4分钟
    nuts_coldcoffe = {
        test = function() return false end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = TUNING.CALORIES_MED,
        sanity = TUNING.SANITY_TINY,
        health = 5,
        perishtime = TUNING.PERISH_MED,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_speed", "nutsbuff_speed")
        end,
        temperature = TUNING.COLD_FOOD_BONUS_TEMP,
        temperatureduration = TUNING.FOOD_TEMP_LONG
    },

    -- 松子拿铁
    -- ————本角色检查台词：加了牛奶，香味更浓了。
    -- ————其他角色检查台词：相比起苦苦的咖啡，我更喜欢这个！
    -- 1蜂蜜，1松果，1冰，1奶制品
    -- +30饱食，+30san，+10血
    -- 保质期20天
    -- xxx20%加速8分钟
    -- 50%加速6分钟
    nuts_latte =
    {
        test = function(cooker, names, tags)
            return tags.sweetener
                and names.pinecone
                and tags.frozen
                and tags.dairy
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 30,
        sanity = 30,
        health = 10,
        perishtime = TUNING.PERISH_PRESERVED,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_speed2", "nutsbuff_speed2")
        end,
    },

    -- 松萝蛋糕卷
    -- ————检查台词：
    -- 1松果，1蜂蜜，2松萝（棱镜的水果）
    -- +50饱食，+10san，+40血
    -- 保质期10天
    -- 食用后砍树效率提升为200%
    nuts_pinecake =
    {
        test = function(cooker, names, tags)
            return names.pinecone -- its a fruit/veggie in Legion steam workshop-1392778117
                and tags.sweetener
                and names.pineananas and names.pineananas > 1
        end,
        priority = 20,
        foodtype = FOODTYPE.GOODIES,
        hunger = 50,
        sanity = TUNING.SANITY_SMALL,
        health = TUNING.HEALING_LARGE,
        perishtime = TUNING.PERISH_MED,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_work", "nutsbuff_work")
        end,
    },

    -- 莓果拿铁
    -- ————本角色检查台词：
    -- ————其他角色检查台词：
    -- 1松果，1奶制品，2浆果
    -- +25饱食，+15san，+20血
    -- 保质期15天
    -- 食用后砍树效率提升为200%
    nuts_berrylatte = {
        test = function(cooker, names, tags)
            local berries_count = 0
            for k, v in pairs(names) do
                if string.match(k, "berries") ~= nil then
                    berries_count = berries_count + v
                    -- print(k)
                end
            end
            -- print(berries_count)
            return names.pinecone
                and tags.dairy
                and berries_count > 1
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = TUNING.CALORIES_MED,
        sanity = TUNING.SANITY_MED,
        health = TUNING.HEALING_MED,
        perishtime = TUNING.PERISH_SLOW,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            -- eater:AddDebuff("nutsbuff_work", "nutsbuff_work")
            eater:AddDebuff("nutsbuff_speed2", "nutsbuff_speed2")
        end,
    },

    -- 香脆松子
    -- ————检查台词：炙烤的酥酥脆脆的松子！好香！
    -- 3松果，1水果度
    -- +15饱食，+5san，+10血
    -- 一次制作两份
    -- 保质期40天
    -- 烹饪时间10秒
    nuts_pinenut = {
        test = function(cooker, names, tags)
            return names.pinecone and names.pinecone > 2
                and tags.fruit and tags.fruit >= 1
        end,
        priority = 9,
        foodtype = FOODTYPE.GOODIES,
        hunger = 15,
        sanity = TUNING.SANITY_TINY,
        health = 10,
        perishtime = TUNING.PERISH_SUPERSLOW,
        cooktime = 0.5,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        stacksize = 2,
    },

    -- 咖啡布丁
    -- ————检查台词：香软嫩滑，如云朵般轻盈的口感。
    -- 2松果，1蜂蜜，1蛋
    -- +35饱食，+5san，+10血
    -- 保质期15天
    -- 提升10%攻击力持续8分钟，提供必忘我茶的回san1分钟
    nuts_pudding = {
        test = function(cooker, names, tags)
            return names.pinecone == 2
                and tags.sweetener
                and tags.egg
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 35,
        sanity = TUNING.SANITY_TINY,
        health = 10,
        perishtime = TUNING.PERISH_SLOW,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_strength", "nutsbuff_strength")
            eater:AddDebuff("sweettea_buff", "sweettea_buff")
        end,
    },

    -- 松果玛奇朵
    -- ————检查台词：嗯，甜度刚刚好！
    -- 1松果，1冰块，2蜂蜜
    -- +25饱食，+10san，+30血
    -- 保质期15天
    -- 升温15秒，提升20%移速4分钟
    nuts_macchiato = {
        test = function(cooker, names, tags)
            return names.pinecone
                and tags.frozen
                and tags.sweetener and tags.sweetener > 1
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 25,
        sanity = TUNING.SANITY_SMALL,
        health = TUNING.HEALING_MEDLARGE,
        perishtime = TUNING.PERISH_SLOW,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_speed", "nutsbuff_speed")
        end,
        temperature = TUNING.HOT_FOOD_BONUS_TEMP,
        temperatureduration = TUNING.FOOD_TEMP_LONG,
    },

    -- 黄油拿铁
    -- ————检查台词：噢！黄油的味道非常浓郁。
    -- 2松果，2奶制品，1黄油（必须）
    -- +20饱食，+5san，+40血
    -- 保质期20天
    -- 提升50%移速12分钟
    nuts_latte_butter = {
        test = function(cooker, names, tags)
            return names.pinecone and names.pinecone > 1
                and tags.dairy and tags.dairy > 1
                and names.butter
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 20,
        sanity = TUNING.SANITY_TINY,
        health = TUNING.HEALING_LARGE,
        perishtime = TUNING.PERISH_PRESERVED,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_speed2", "nutsbuff_speed2")
            local buff = eater:GetDebuff("nutsbuff_speed2")
            if buff then
                buff.components.timer:SetTimeLeft("buffover", TUNING.NUTSBUFF_LATTE_BUTTER_DURATION)
            end
        end,
        temperature = TUNING.HOT_FOOD_BONUS_TEMP,
        temperatureduration = TUNING.FOOD_TEMP_LONG,
    },

    -- 香浓摩卡
    -- ————检查台词：在寒冷的冬天来上这么一杯，真的太棒了！
    -- 2松果，1冰，1烤桦栗果（必须）
    -- +25饱食，+20san，+10血
    -- 保质期20天
    -- 保持不会过冷6分钟
    nuts_mocha = {
        test = function(cooker, names, tags)
            return names.pinecone and names.pinecone > 1
                and tags.frozen
                and names.acorn_cooked
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 25,
        sanity = TUNING.SANITY_MEDLARGE,
        health = 10,
        perishtime = TUNING.PERISH_PRESERVED,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        potlevel = "low",
        ---------------------
        temperature = TUNING.HOT_FOOD_BONUS_TEMP,
        temperatureduration = 6 * 60,
    },

    -- 香蕉拿铁
    -- ————检查台词：非常意外，香蕉让咖啡多了点清甜的味道！
    -- 2松果，1奶制品，1香蕉
    -- +35饱食，+33san，+10血
    -- 保质期20天
    -- 加速50%，6分钟，猴子不会主动跟随你，不会偷你东西6分钟
    nuts_latte_banana = {
        test = function(cooker, names, tags)
            return names.pinecone and names.pinecone > 1
                and tags.dairy
                and (names.cave_banana or names.cave_banana_cooked)
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 35,
        sanity = TUNING.SANITY_LARGE,
        health = 10,
        perishtime = TUNING.PERISH_PRESERVED,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            eater:AddDebuff("nutsbuff_speed2", "nutsbuff_speed2")
            eater:AddDebuff("nutsbuff_banana", "nutsbuff_banana")
        end,
    },

    -- 大麦茶
    -- ————检查台词：来上一杯，我感觉世界都宁静了。
    -- 2松果，1树枝，1桦栗果/石果
    -- +10饱食，+10san，+5血
    -- 保质期20天
    -- 使人物当前温度调整为世界温度（平衡体温，冬天变为50度，夏天10度，秋冬30度）
    nuts_barleytea = {
        test = function(cooker, names, tags)
            return names.pinecone and names.pinecone > 1
                and names.twigs
                and (names.acorn_cooked or names.acorn or names.rock_avocado_fruit_ripe or names.rock_avocado_fruit_ripe_cooked)
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 10,
        sanity = TUNING.SANITY_SMALL,
        health = 5,
        perishtime = TUNING.PERISH_PRESERVED,
        cooktime = 0.5,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater)
            if eater.components.temperature then
                eater.components.temperature:SetTemperature(TUNING.NUTS_BARLEYTEA_TEMPERATURE[string.upper(TheWorld.state.season)] or TUNING.BOOK_TEMPERATURE_AMOUNT)
            end
        end,
    },


    -- 松果小零食
    -- ————检查台词：坚果小零食，对于我的牙齿来说可能有些硬了。
    -- 2松果，2石果
    -- +200牛牛饱食
    -- 保质期40天
    -- 随机驯化+1%
    nuts_beefalofeed = {
        test = function(cooker, names, tags)
            return names.pinecone and names.pinecone > 1
                and ((names.rock_avocado_fruit_ripe or 0) + (names.rock_avocado_fruit_ripe_cooked or 0) > 1)
        end,
        priority = 10,
        foodtype = FOODTYPE.ROUGHAGE,
        hunger = 200,
        sanity = 0,
        health = 0,
        perishtime = TUNING.PERISH_SUPERSLOW,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater, feeder)
            if inst.components.domesticatable and TENDENCY ~= nil then
                -- inst.components.domesticatable:DeltaDomestication(TUNING.NUTS_BEEFALOFEED_DOMESTICATION, feeder)
                inst.components.domesticatable:DeltaTendency(GetRandomItem(TENDENCY), TUNING.NUTS_BEEFALOFEED_DOMESTICATION)
            end
        end,
    },

    -- 万圣零食袋
    -- ————检查台词：在南瓜侧面打几个孔真的不会让糖果漏出来吗？
    -- 开启游戏内万圣节后才可制作
    -- 1松果，1南瓜，2蜂蜜
    -- 无耐久，制作后为一个手部装备，不可堆叠，
    -- 装备在手上时有4个格子，仅可放入万圣节糖果
    -- 放在地上会散发微弱光芒（和阿的那个生日蛋糕一样的光）
    -- 可鼠标拿起对准人物食用，回复+35饱食，+0san，+0血。
    -- 里面每有一个糖果，+1san，+1血，叠加无上限
    nuts_candybag = {
        test = function(cooker, names, tags)
            return IsSpecialEventActive(SPECIAL_EVENTS.HALLOWED_NIGHTS)
                and names.pinecone
                and names.pumpkin
                and tags.sweetener and tags.sweetener > 1
        end,
        priority = 20,
        foodtype = FOODTYPE.GOODIES,
        hunger = 35,
        sanity = 0,
        health = 0,
        -- perishtime = TUNING.PERISH_SUPERSLOW,
        cooktime = 1,
        scale = 1.5,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        potlevel = "low",
        ---------------------
        oneatenfn = function(inst, eater, feeder)
            if inst.components.container then
                local candies = inst.components.container:RemoveAllItems()
                local count = 0
                for k, v in pairs(candies) do
                    if v.components.stackable then
                        count = count + v.components.stackable:StackSize()
                    end
                    v:Remove()
                end
                if count > 0 then
                    if eater.components.sanity ~= nil then
                        eater.components.sanity:DoDelta(count)
                    end
                    if eater.components.health ~= nil and eater.components.oldager == nil then
                        eater.components.health:DoDelta(count, nil, "nuts_candybag")
                    end
                end
            end
        end,
        nostack = true,
        nospice = true,
        masterfn = function(inst)
            inst._light = SpawnPrefab("nuts_candylight")
            inst._light.entity:SetParent(inst.entity)
            inst._light.parent = inst

            inst.components.inventoryitem:SetOnDroppedFn(lightson)
            inst.components.inventoryitem:SetOnPutInInventoryFn(lightsoff)

            inst:AddComponent("equippable")
            inst.components.equippable:SetOnEquip(onequip)
            inst.components.equippable:SetOnUnequip(onunequip)

            inst:AddComponent("container")
            inst.components.container:WidgetSetup("nuts_candybag")
            inst.components.container.canbeopened = false

            inst.OnRemoveEntity = function(inst)
                inst._light:Remove()
                inst._light = nil
            end
        end,
    },
}
local foods2 = {
    -- 青饺（素食）（本mod第一个素食估计也是唯一一个，因为其他都是好登西）
    -- ————检查台词：绿色的饺子，带着清新的春天的味道！
    -- （春天才能制作）
    -- 1松果，0.5肉，1玉米，1胡萝卜
    -- +120饱食，+10san，+20血
    -- 保质期25天
    -- 清空当前湿度，且6分钟内不会潮湿
    nuts_dumpling = {
        test = function(cooker, names, tags)
            return (isspring() or TUNING.SEASONAL_FOOD == true)
                and names.pinecone
                and tags.meat
                and names.corn
                and names.carrot
        end,
        priority = 10,
        foodtype = FOODTYPE.VEGGIE,
        hunger = 120,
        sanity = 10,
        health = 20,
        perishtime = 25 * TUNING.PERISH_ONE_DAY,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        -- -- --
        -- overridesymbolname = "",
        -- potlevel = "low",
        oneatenfn = function(inst, eater, feeder)
            eater:AddDebuff("nutsbuff_moisture", "nutsbuff_moisture")
        end
    },

    -- 绿豆汤（好东西类料理）
    -- ————检查台词：听说南北方的绿豆汤颜色不同，这是真的吗？
    -- （夏天才能制作）
    -- 1松果，1冰，2西瓜
    -- +60饱食，+10san，+5血
    -- 保质期15天
    -- 提供降温12分钟
    nuts_mungbean_soup = {
        test = function(cooker, names, tags)
            return (issummer() or TUNING.SEASONAL_FOOD == true)
                and names.pinecone
                and tags.frozen
                and names.watermelon == 2
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 60,
        sanity = 10,
        health = 5,
        perishtime = TUNING.PERISH_SLOW,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        potlevel = "low",
        temperature = TUNING.COLD_FOOD_BONUS_TEMP,
        temperatureduration = 12 * mins,
    },

    -- 红薯糖水（好东西）
    -- ————检查台词：寒冷的冬天来上这么一碗，整个人都暖和起来了。
    -- （冬天才能制作）
    -- 1松果，2南瓜，1萝卜（蔬菜度大于等于3）
    -- +125饱食，+15san，+30血
    -- 保质期20天
    -- 保持温度不过冷16分钟
    nuts_sweetpotato_soup = {
        test = function(cooker, names, tags)
            return (iswinter() or TUNING.SEASONAL_FOOD == true)
                and names.pinecone
                and names.pumpkin == 2
                and names.carrot
        end,
        priority = 10,
        foodtype = FOODTYPE.GOODIES,
        hunger = 125,
        sanity = 15,
        health = 30,
        perishtime = TUNING.PERISH_PRESERVED,
        cooktime = 1,
        floater = { "small", 0.05, 0.7 },
        potlevel = "low",
        temperature = TUNING.HOT_FOOD_BONUS_TEMP,
        temperatureduration = 16 * mins,
    },
}

-- 松间云雾·奶茶（好东西类料理）
-- ————检查台词：茶香，奶香，完美融合在一起，这就是美味的奶茶！
-- （秋天才能制作）
-- 1松果，1蜂蜜，2南瓜
-- +15饱食，+60san，+10血
-- 保质期20天
-- 每2秒回复1点san值，持续1分钟
-- ↓↓↓在火上加热后变为以下这个↓↓↓新鲜度重置
foods2["nuts_mistypine"] = {
    test = function(cooker, names, tags)
        return (isfall() or TUNING.SEASONAL_FOOD == true)
            and names.pinecone
            and tags.sweetener
            and names.pumpkin == 2
    end,
    priority = 10,
    foodtype = FOODTYPE.GOODIES,
    hunger = 15,
    sanity = 60,
    health = 10,
    perishtime = TUNING.PERISH_PRESERVED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    potlevel = "low",
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nutsbuff_sanity", "nutsbuff_sanity")
    end,
    masterfn = function(inst)
        inst:AddComponent("cookable")
        inst.components.cookable.product = "nuts_mistypine_hot"
    end
}
-- 热的松间云雾·奶茶（好东西类料理）
-- ————检查台词：来一杯热奶茶！
-- +15饱食，+60san，+10血
-- 保质期10天
-- 提供升温30秒，每2秒回复1点san值，持续1分钟
foods2["nuts_mistypine_hot"] = {
    test = function(cooker, names, tags) return false end,
    priority = -1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 15,
    sanity = 60,
    health = 10,
    perishtime = TUNING.PERISH_MED,
    cooktime = 0.1,
    floater = { "small", 0.05, 0.7 },
    temperature = TUNING.HOT_FOOD_BONUS_TEMP,
    temperatureduration = seg_time,
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nutsbuff_sanity", "nutsbuff_sanity")
    end
}

-- 桂馥兰香·奶茶（好东西类料理）
-- ————检查台词：茶香，奶香，完美融合在一起，这就是美味的奶茶！
-- （秋天才能制作）
-- 1松果，1蜂蜜，1南瓜，1兰花瓣
-- +35饱食，+60san，+20血
-- 保质期20天
-- 每2秒回复1点san值，持续2分钟
foods2["nuts_osmanthus"] = {
    test = function(cooker, names, tags)
        return (isfall() or TUNING.SEASONAL_FOOD == true)
            and names.pinecone
            and tags.sweetener
            and (names.pumpkin or names.pumpkin_cooked)
            and names.petals_orchid
    end,
    priority = 10,
    foodtype = FOODTYPE.GOODIES,
    hunger = 35,
    sanity = 60,
    health = 20,
    perishtime = TUNING.PERISH_PRESERVED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    potlevel = "low",
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nutsbuff_sanity", "nutsbuff_sanity")
        local buff = eater:GetDebuff("nutsbuff_sanity")
        if buff then
            buff.components.timer:SetTimeLeft("buffover", TUNING.NUTSBUFF_OSMANTHUS_SANITY_DURATION)
        end
    end,
    masterfn = function(inst)
        inst:AddComponent("cookable")
        inst.components.cookable.product = "nuts_osmanthus_hot"
    end
}
-- ↓↓↓在火上加热后变为以下这个↓↓↓新鲜度重置
-- 热的桂馥兰香·奶茶（好东西类料理）
-- ————检查台词：来一杯热奶茶！
-- +35饱食，+60san，+20血
-- 保质期10天
-- 提供升温30秒，每2秒回复1点san值，持续2分钟
foods2["nuts_osmanthus_hot"] = {
    test = function(cooker, names, tags) return false end,
    priority = -1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 35,
    sanity = 60,
    health = 20,
    perishtime = TUNING.PERISH_PRESERVED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    temperature = TUNING.HOT_FOOD_BONUS_TEMP,
    temperatureduration = seg_time,
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nutsbuff_sanity", "nutsbuff_sanity")
        local buff = eater:GetDebuff("nutsbuff_sanity")
        if buff then
            buff.components.timer:SetTimeLeft("buffover", TUNING.NUTSBUFF_OSMANTHUS_SANITY_DURATION)
        end
    end,
}
foods2["nuts_osmanthus2"] = deepcopy(foods2["nuts_osmanthus"])
foods2["nuts_osmanthus2"].commonfn = function(inst)
    inst:SetPrefabNameOverride("nuts_osmanthus")
end
foods2["nuts_osmanthus2"].masterfn = function(inst)
    inst:AddComponent("cookable")
    inst.components.cookable.product = "nuts_osmanthus2_hot"
end
foods2["nuts_osmanthus2_hot"] = deepcopy(foods2["nuts_osmanthus_hot"])
foods2["nuts_osmanthus2_hot"].commonfn = function(inst)
    inst:SetPrefabNameOverride("nuts_osmanthus_hot")
end


-- 可能被塞了钱的饺子
-- ————检查台词：我能吃到那枚代表了好运的铜钱吗？
-- 1松果，1蛋，1大肉，1玉米
-- +35饱食，+10san，+20血
-- 保质期8天
-- 一次烹饪两份，短时间内连续吃两个会获得1枚金块

foods2["nuts_dumpling2"] = {
    test = function(cooker, names, tags)
        return names.pinecone
            and tags.egg
            and tags.meat and tags.meat >= 1
            and names.corn
    end,
    priority = 10,
    foodtype = FOODTYPE.MEAT,
    hunger = 35,
    sanity = 10,
    health = 20,
    perishtime = TUNING.PERISH_FASTISH,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    scale = 1.1,
    stacksize = 2,
    oneatenfn = function(inst, eater, feeder)
        if eater._just_ate_nuts_dumpling2 then
            eater._just_ate_nuts_dumpling2:Cancel()
            eater._just_ate_nuts_dumpling2 = nil
            if eater.components.inventory then
                eater.components.inventory:GiveItem(SpawnPrefab("goldnugget"))
            else
                LaunchAt(SpawnPrefab("goldnugget"), eater, nil, 0.25)
            end
        else
            eater._just_ate_nuts_dumpling2 = eater:DoTaskInTime(8, function(eater)
                if eater._just_ate_nuts_dumpling2 then
                    eater._just_ate_nuts_dumpling2:Cancel()
                    eater._just_ate_nuts_dumpling2 = nil
                end
            end)
        end
    end,
}

-- 白玉汤圆——元宵
-- ————检查台词：你选择元宵还是汤圆？
-- 2松果，1蜂蜜，1蔬菜
-- +55饱食，+10san，+30血
-- 保质期10天
foods2["nuts_tangyuan"] = {
    test = function(cooker, names, tags)
        return names.pinecone and names.pinecone > 1
            and tags.sweetener
            and tags.veggie and tags.veggie >= 1
    end,
    priority = 10,
    foodtype = FOODTYPE.GOODIES,
    hunger = 55,
    sanity = 10,
    health = 30,
    perishtime = TUNING.PERISH_MED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    scale = 1.2,
}

-- 粽子——端午
-- ————检查台词：有个传统是把粽子丢水里让鱼吃是吗？
-- 1松果，1水果，1.5蔬菜
-- +45饱食，+5san，+10血
-- 保质期20天
foods2["nuts_zongzi"] = {
    test = function(cooker, names, tags)
        return names.pinecone
            and tags.fruit and tags.fruit >= 1
            and tags.veggie and tags.veggie >= 1.5
    end,
    priority = 10,
    foodtype = FOODTYPE.GOODIES,
    hunger = 45,
    sanity = 5,
    health = 10,
    perishtime = TUNING.PERISH_PRESERVED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    scale = 1.2,
}

-- “在水里，在天上，在心中”（中秋特别彩蛋料理）（玉兔联动料理，开启玉兔mod才可制作）（开启玉兔mod后，材料“月树花”可入锅）
-- ————其他角色检查台词：句句不提月亮，句句说的月亮。
-- ————玉兔检查台词：
-- 2松果，2月树花
-- +25饱食，+40san，+20血
-- 保质期15天
-- 每2秒回复1点san，持续2分钟，玉兔食用后在2分钟内san不降低（不会因为任何buff与光环降低）
foods2["nuts_mooncake"] = {
    test = function(cooker, names, tags)
        return names.pinecone and names.pinecone > 1
            and names.moon_tree_blossom and names.moon_tree_blossom > 1
    end,
    priority = 10,
    foodtype = FOODTYPE.GOODIES,
    hunger = 25,
    sanity = 40,
    health = 20,
    perishtime = TUNING.PERISH_SLOW,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    scale = 1.1,
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nutsbuff_sanity", "nutsbuff_sanity")
        local buff = eater:GetDebuff("nutsbuff_sanity")
        if buff then
            buff.components.timer:SetTimeLeft("buffover", TUNING.NUTSBUFF_SANITY_MOONCAKE_DURATION)
        end

        if eater.prefab == "yutu" then
            eater:AddDebuff("nutsbuff_yutu", "nutsbuff_yutu")
        end
    end
}

-- 不断回响的时光
-- 提升20%移速6分钟
foods2["nuts_echotime"] = {
    test = function(cooker, names, tags)
        return names.pinecone and tags.frozen and tags.frozen > 1 and names.nightmarefuel
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 25,
    sanity = 35,
    health = 10,
    perishtime = TUNING.PERISH_SLOW,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nuts_buff_echotime", "nuts_buff_echotime")
    end
}

-- 于火光中映照出来
-- 提升睡眠抗性8分钟，拉姆饮用后额外获得：不会潮湿，不会被冰冻8分钟
foods2["nuts_flameborn"] = {
    test = function(cooker, names, tags)
        return names.pinecone == 2 and tags.frozen and names.wuyi_lambris_firerock
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 15,
    sanity = 60,
    health = -5,
    perishtime = TUNING.PERISH_SLOW,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        -- 立马清醒
        if eater.components.grogginess ~= nil and
            not (eater.components.health ~= nil and eater.components.health:IsDead())
            and not eater:HasTag("playerghost") then
            eater.components.grogginess:ResetGrogginess()
        end
        eater:AddDebuff("nuts_buff_flameborn", "nuts_buff_flameborn")
    end
}

-- 回忆里,在此处
-- 提升睡眠抗性8分钟，莱茵饮用后额外提升20点位面伤害
foods2["nuts_memorybound"] = {
    test = function(cooker, names, tags)
        return names.pinecone and tags.frozen and names.moon_cap and names.dragonfruit
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 25,
    sanity = 50,
    health = 10,
    perishtime = TUNING.PERISH_SLOW,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        -- 立马清醒
        if eater.components.grogginess ~= nil and
            not (eater.components.health ~= nil and eater.components.health:IsDead())
            and not eater:HasTag("playerghost") then
            eater.components.grogginess:ResetGrogginess()
        end
        eater:AddDebuff("nuts_buff_memorybound", "nuts_buff_memorybound")
    end
}

-- 兔子血
-- 提升人物20%攻击力8分钟，加洛普饮用后额外提供每次攻击5点吸血8分钟
foods2["nuts_rabbit_blood"] = {
    test = function(cooker, names, tags)
        return names.pinecone and tags.frozen and names.gallop_reviver and names.rabbit
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 25,
    sanity = 20,
    health = 5,
    perishtime = TUNING.PERISH_MED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nuts_buff_rabbit_blood", "nuts_buff_rabbit_blood")
    end
}

-- 蔷薇拿铁
-- 提供20%加速8分钟，每1秒回1血持续30秒
foods2["nuts_rosy_latte"] = {
    test = function(cooker, names, tags)
        return names.pinecone and tags.sweetener and names.petals_rose == 2
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 35,
    sanity = 10,
    health = 20,
    perishtime = TUNING.PERISH_PRESERVED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nuts_buff_rosy_latte", "nuts_buff_rosy_latte")
        eater:AddDebuff("nuts_buff_rosy_latte1", "nuts_buff_rosy_latte1")
    end
}

-- 看见一弯银轮
-- 获得植物人开花照料作物效果,玉兔在月圆这一天饮用额外回复55san,10血
foods2["nuts_silver_crescent"] = {
    test = function(cooker, names, tags)
        return names.pinecone and tags.frozen and names.moon_cap and names.yutu_xin_shen
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 25,
    sanity = 20,
    health = 5,
    perishtime = TUNING.PERISH_SLOW,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nuts_buff_silver_crescent", "nuts_buff_silver_crescent")
        if eater.prefab == "yutu" and TheWorld.state.moonphase == "full" then
            eater.components.sanity:DoDelta(55)
            eater.components.health:DoDelta(10, nil, "nuts_silver_crescent")
        end
    end
}

-- 松香脆肠卷
-- 食用后所有生物仇恨度下降
-- 该食谱优先度得高于500，不然会被该mod其他料理覆盖
foods2["nuts_pine_sausage_roll"] = {
    test = function(cooker, names, tags)
        return names.pinecone == 2 and tags.fat and names.weisuo_clean_intestine
    end,
    priority = 600,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 35,
    sanity = 15,
    health = 40,
    perishtime = TUNING.PERISH_MED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nuts_buff_pine_sausage_roll", "nuts_buff_pine_sausage_roll")
    end
}

-- 开心果拿铁
-- 食用后所有生物仇恨度下降提供20%加速8分钟，食用后获得大蒜调味效果，持续时间同大蒜粉
foods2["nuts_pistachio_latte"] = {
    test = function(cooker, names, tags)
        return names.pinecone and tags.sweetener and names.rock_avocado_fruit_ripe == 2
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.GOODIES,
    hunger = 40,
    sanity = 10,
    health = 10,
    perishtime = TUNING.PERISH_PRESERVED,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    oneatenfn = function(inst, eater, feeder)
        eater:AddDebuff("nuts_buff_pistachio_latte", "nuts_buff_pistachio_latte")
        eater:AddDebuff("nuts_buff_pistachio_latte1", "nuts_buff_pistachio_latte1")
    end
}

-- 超级香甜粘玉米
-- 食用后有5%概率使人物扣20血，获得1骨头碎片，并且4分钟内无法再食用任何东西
foods2["nuts_sticky_corn"] = {
    test = function(cooker, names, tags)
        return names.pinecone and tags.frozen and names.corn == 2
    end,
    priority = 30,
    weight = 1,
    foodtype = FOODTYPE.VEGGIE,
    hunger = 100,
    sanity = 60,
    health = 5,
    perishtime = TUNING.PERISH_TWO_DAY,
    cooktime = 1,
    floater = { "small", 0.05, 0.7 },
    potlevel = "low",
    oneatenfn = function(inst, eater, feeder)
        if math.random() < 0.05 and eater.components.eater and eater:HasTag("player") then
            eater:AddDebuff("nuts_buff_sticky_corn", "nuts_buff_sticky_corn")
        end
    end,
}

-- 食趣联动料理,无特殊buff
local foods3 = {
    -- 松仁玉米虾仁--联动
    tf_corn_pine_nut_shrimp =
    {
        test = function(cooker, names, tags)
            return names.pinecone == 2 and names.corn == 1
                and (names.tf_green_shrimp_meat == 1 or names.tf_green_shrimp_meat_cooked == 1 or names.tf_green_shrimp == 1)
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.MEAT,
        health = 30,
        hunger = 75,
        perishtime = 16 * TUNING.TOTAL_DAY_TIME,
        sanity = 12.5,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "pinecone", 2 }, { "corn", 1 }, { "tf_green_shrimp", 1 } } },
    },
    -- 提拉米苏杯--联动
    tf_tiramisu =
    {
        test = function(cooker, names, tags)
            return names.pinecone == 1 and names.tf_strawberry == 1 and tags.sweetener and tags.fat
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 67.5,
        hunger = 67.5,
        perishtime = 20 * TUNING.TOTAL_DAY_TIME,
        sanity = 67.5,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "pinecone", 1 }, { "tf_strawberry", 1 }, { "honey", 1 }, { "butter", 1 } } },
    },
    -- 香脆蝴蝶曲奇--联动
    tf_butterfly_pastry =
    {
        test = function(cooker, names, tags)
            return names.butterflywings == 2 and names.pinecone == 2
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 13.5,
        hunger = 15.5,
        perishtime = 20 * TUNING.TOTAL_DAY_TIME,
        sanity = 25,
        cooktime = 1,
        stacksize = 2, -- 一次做两个
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "butterflywings", 2 }, { "pinecone", 2 } } },
    },
    -- 海盐奶绿--联动
    tf_sea_salt_milk_tea =
    {
        test = function(cooker, names, tags)
            return names.pinecone == 1 and names.foliage == 1 and names.ice == 1 and tags.sweetener
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.VEGGIE,
        health = 20,
        hunger = 12.5,
        perishtime = 12 * TUNING.TOTAL_DAY_TIME,
        sanity = 75,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "sea_watermelon", 1 }, { "ice", 1 }, { "butter", 1 }, { "honey", 1 } } },
    },
}

if not ENABLEDMODS.tastefun then
    for k, v in pairs(foods3) do
        if not v.overridebuild then
            v.overridebuild = "nutsfood3"
        end
        foods[k] = v
    end
end

for k, v in pairs(foods2) do
    if not v.overridebuild then
        v.overridebuild = "nutsfood2"
    end
    foods[k] = v
end

for k, v in pairs(foods) do
    v.name = k
    v.weight = v.weight or 1
    v.priority = v.priority or 0

    if not v.basename then
        v.basename = k
    end

    if not v.overridebuild then
        v.overridebuild = "nutsfood"
    end

    if not v.cookbook_atlas then
        -- v.cookbook_tex = v.name..".tex"
        v.cookbook_atlas = "images/cookbook_images/" .. v.name .. ".xml"
    end

    v.cookbook_category = "cookpot"
end

return foods
